from django.db import models
from django.core.validators import MinValueValidator

class Product(models.Model):
    """商品模型"""
    name = models.CharField('商品名称', max_length=100)
    description = models.TextField('商品描述', blank=True)
    price = models.DecimalField('价格', max_digits=10, decimal_places=2, validators=[MinValueValidator(0)])
    stock = models.IntegerField('库存', default=0, validators=[MinValueValidator(0)])
    image = models.ImageField('商品图片', upload_to='products/', blank=True, null=True)
    created_at = models.DateTimeField('创建时间', auto_now_add=True)
    updated_at = models.DateTimeField('更新时间', auto_now=True)

    class Meta:
        verbose_name = '商品'
        verbose_name_plural = '商品'
        ordering = ['-created_at']

    def __str__(self):
        return self.name
